package com.ruoyi.project.module.name.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.name.domain.Name;
import com.ruoyi.project.module.name.service.INameService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 测试 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-06
 */
@Controller
@RequestMapping("/module/name")
public class NameController extends BaseController
{
    private String prefix = "module/name";
	
	@Autowired
	private INameService nameService;
	
	@RequiresPermissions("module:name:view")
	@GetMapping()
	public String name()
	{
	    return prefix + "/name";
	}
	
	/**
	 * 查询测试列表
	 */
	@RequiresPermissions("module:name:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Name name)
	{
		startPage();
        List<Name> list = nameService.selectNameList(name);
		return getDataTable(list);
	}
	
	/**
	 * 新增测试
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存测试
	 */
	@RequiresPermissions("module:name:add")
	@Log(title = "测试", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Name name)
	{		
		return toAjax(nameService.insertName(name));
	}

	/**
	 * 修改测试
	 */
	@GetMapping("/edit/{nameId}")
	public String edit(@PathVariable("nameId") Integer nameId, ModelMap mmap)
	{
		Name name = nameService.selectNameById(nameId);
		mmap.put("name", name);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存测试
	 */
	@RequiresPermissions("module:name:edit")
	@Log(title = "测试", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Name name)
	{		
		return toAjax(nameService.updateName(name));
	}
	
	/**
	 * 删除测试
	 */
	@RequiresPermissions("module:name:remove")
	@Log(title = "测试", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(nameService.deleteNameByIds(ids));
	}
	
}
